package com.topfinance.payment.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.BeanUtils;

import com.topfinance.cnaps2.ebo.ConfOutPortEbo;
import com.topfinance.frame.dao.HibernateEntityDao;
import com.topfinance.frame.exception.AppException;
import com.topfinance.payment.dto.TCfgOutPortDto;
import com.topfinance.payment.ebo.TCfgFormatEbo;
import com.topfinance.payment.ebo.TCfgNodeEbo;
import com.topfinance.payment.ebo.TCfgPortOutEbo;
import com.topfinance.payment.ebo.TCfgTransOutEbo;
import com.topfinance.payment.service.ITCfgPortOutMgr;

/**
 * 该类自动实现了dao的一般方法，如add, remove, update
 * 在service中出现的大部分情况下是在向后台提交数据前的处理(如校验)及获取后台数据后的处理等
 * @author
 *
 */

public class TCfgPortOutMgrImpl extends HibernateEntityDao<TCfgPortOutEbo> implements ITCfgPortOutMgr {

	private static final Log log = LogFactory.getLog(TCfgPortOutMgrImpl.class);
	
	public void deleteTCfgPortOut(Integer oid) throws AppException{
		removeById(TCfgPortOutEbo.class,oid);
	}

	//获得传输协议列表
	public List<TCfgPortOutEbo> getAllPortOut() throws AppException{
		String hql = " from TCfgPortOutEbo t " ;
		String where = "";
		List<Object> paramList = new ArrayList<Object>();
		if (isNotBlank(where)) {
			where = " where " + where;
		}
		hql = hql + where;
		return find(hql,paramList.toArray());		
	}

	public TCfgPortOutEbo getOutPort(Integer oid) throws AppException {
		// TODO Auto-generated method stub
		return (TCfgPortOutEbo)get(oid);
	}

	public TCfgPortOutEbo addOutPort(TCfgOutPortDto o) throws AppException {
		TCfgNodeEbo no = (TCfgNodeEbo)get(TCfgNodeEbo.class,o.getNID());
		TCfgTransOutEbo to = (TCfgTransOutEbo)get(TCfgTransOutEbo.class,o.getTID());
		TCfgFormatEbo fo = (TCfgFormatEbo)get(TCfgFormatEbo.class,o.getfID());
		TCfgPortOutEbo p = new TCfgPortOutEbo();
		BeanUtils.copyProperties(o, p);
		p.setTCfgNode(no);
		p.setTCfgTransOut(to);
		p.setTCfgFormat(fo);
		save(p);
		return p;
	}

	public void deleteOutPort(TCfgOutPortDto o) throws AppException {
		// TODO Auto-generated method stub
		removeById(ConfOutPortEbo.class,o.getOid());
	}

	public void deleteOutPort(Integer id) throws AppException {
		// TODO Auto-generated method stub
		removeById(TCfgPortOutEbo.class,id);
	}

	public void editOutPort(TCfgOutPortDto o) throws AppException {
		// TODO Auto-generated method stub
		TCfgNodeEbo no = (TCfgNodeEbo)get(TCfgNodeEbo.class,o.getNID());
		TCfgTransOutEbo to = (TCfgTransOutEbo)get(TCfgTransOutEbo.class,o.getTID());
		TCfgFormatEbo fo = (TCfgFormatEbo)get(TCfgFormatEbo.class,o.getfID());
		TCfgPortOutEbo p = new TCfgPortOutEbo();
		BeanUtils.copyProperties(o, p);
		p.setTCfgNode(no);
		p.setTCfgTransOut(to);
		p.setTCfgFormat(fo);
		update(p);
	}
}
